from fisheye_manager import FisheyeManager
import fisheye_consts

class BatteryManager():
    """
    A class which is responsible for managing the battery of the node.
    """
    def __init__(self, node_id):
        """
        Constructor.
        """
        self._node_id = node_id
        self._power = fisheye_consts.FISHEYE_NODE_CELL_POWER
        
    def validate_send(self, next_hop_id, packet_size):
        """
        Validates that the node has enough power for sending a packet.
        """
        distance = FisheyeManager().get_distance(self._node_id, next_hop_id)
        needed_power = packet_size * fisheye_consts.FISHEYE_FRAGMENT_TRANSFER_NEEDED_POWER_K * \
                        (distance ** fisheye_consts.FISHEYE_FRAGMENT_TRANSFER_NEEDED_POWER_C)
        
        if self._power <= needed_power:
            raise Exception("Not enought power to send the packet!")
        else:
            self._power -= needed_power
            
      
